package com.design.享元模式;

import java.util.HashMap;

public class FlyweightFactory {

	private static HashMap<String , Flyweight> pool = new HashMap<>();
	
	public static Flyweight getFlyweight(String extrinsic) {
		Flyweight flyweight = null;
		
		if(pool.containsKey(extrinsic)) {
			flyweight = pool.get(extrinsic);
			System.out.println("pool 中已经存在......");
		}else {
			flyweight = new ConcreteFlyweight(extrinsic);
			pool.put(extrinsic,flyweight);
			System.out.println("创新新的 flyweight");
		}
		return flyweight;
	}
	
}
